package com.example.payer

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.payer.databinding.ActivityFinishDetailBinding
import com.example.payer.vm.PayerViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import kotlin.random.Random

@AndroidEntryPoint
@Route(path = "/payer/FinishDetailActivity")
class FinishDetailActivity : BaseMvvmActivity<ActivityFinishDetailBinding>() {

    private val finishDetailViewModel:PayerViewModel by viewModels()
    @Autowired
    @JvmField
    var id:Int = 0
    override fun initView() {
        ARouter.getInstance().inject(this)
        val year1 = SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis())
        val year2 = SimpleDateFormat("2026-MM-dd").format(System.currentTimeMillis())
        var week = "${year1}至${year2}"
        var random = Random.nextInt(8999999)+9000000
        finishDetailViewModel.getPayerDetail(id)
        finishDetailViewModel.mPayerDetailSuccess.observe(this){
            mDataBinding.tvNumber.text = "交易流水号: ${random.toString()}"
            mDataBinding.tvAddress.text = "天津八维培训学校"
            mDataBinding.tvMoney.text = week
            mDataBinding.tvOne.text = "￥${it.chargeAmount}"
            mDataBinding.tvCount.text = "${1}"
            mDataBinding.tvReceivableAmount.text = "￥${it.discountAmount}"
            mDataBinding.tvPenalty.text = "￥${it.penalty}"
            mDataBinding.tvChargeAmount.text = "￥${it.chargeAmount}"
            mDataBinding.tvBalanceDeduction.text = "￥${it.balanceDeduction}"
            mDataBinding.tvActualAmount.text = "￥${it.actualAmount}"
            mDataBinding.tvZfb.text = it.paymentMethod
            mDataBinding.tvPayerTime.text = SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis())
            mDataBinding.tvOperator.text = it.operator
        }
        finishDetailViewModel.mError.observe(this){
            ToastUtils.showLong("进入失败")
        }
    }

    override fun getLayoutId(): Int =R.layout.activity_finish_detail
}